import Vue from 'vue'
import VueRouter from 'vue-router'
import login from '../components/login.vue'
import home from '../components/home.vue'
import user2 from '../components/power/user2.vue'
import user from '../components/user/uesr.vue' 
import user1 from '../components/power/user1.vue'
import Cate from '../components/goods/Cate.vue'
import Params from '../components/goods/Params.vue'
import List from '../components/goods/List.vue'
import Add from  '../components/goods/Add.vue'
import Order from '../components/order/Order.vue'
import Reporg from '../components/reporg/Reporg.vue'






Vue.use(VueRouter)

  const routes = [
	{
		  path: '/', redirect: '/login'
	},
    {
		path: '/login', component:login
	},
	{
		path: '/home', component:home,

		    children: [
		  
		      { path: '/user', component:user },
					{ path: '/user2', component:user2 },
					{ path: '/user1', component:user1 },
					{ path: '/user5', component: Cate },
					{ path: '/user4', component:Params },
					{ path: '/user3', component:List },
					{ path: '/goods/add', component:Add },
					{ path: '/user6', component:Order },
					{ path: '/user7', component:Reporg }
		  
		    ] 

	


	}
]

const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
	if(to.path === '/login') return next ()
	const tokenStr = window.sessionStorage.getItem('token')
	if(!tokenStr) return next('/login')
	
	
		next()

	
	
})
 
export default router
